package com.betfair.wrapper.types;

import com.betfair.www.publicapi.types.exchange.v5.*;
import com.betfair.www.publicapi.types.exchange.v5.Runner;
import org.hibernate.annotations.*;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: markwilliams
 * Date: 10/19/13
 * Time: 1:54 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "Market", uniqueConstraints = {
        @UniqueConstraint(columnNames = "iMarketId")})
public class MarketWrap {
    int _id;
    Market _market = new Market();
    Event _event = null;
    MarketPrice _marketPrice = null;
    Map<Integer, Runner> _runners = new HashMap<Integer, Runner>();

    public MarketWrap() {
        _marketPrice = new MarketPrice();
        _marketPrice.setMarket(this);
    }

    public MarketWrap(Market market) {
        this._market = market;
        this._runners = new HashMap<Integer, Runner>();
        if (this._market.getRunners().getRunner() != null && this._market.getRunners().getRunner().length > 0) {
            for (Runner runner : this._market.getRunners().getRunner()) {
                this._runners.put(runner.getSelectionId(), runner);
            }
        }
    }

    @Id
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    @Column(name = "iMarketId")
    public int getId() {
        return _id;
    }

    public void setId(int id) {
        this._id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "iEventId", nullable = false)
    public Event getEvent() {
        return _event;
    }

    public void setEvent(Event event) {
        this._event = event;
    }

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "market")
    @Cascade({CascadeType.SAVE_UPDATE})
    public MarketPrice getMarketPrice() {
        return _marketPrice;
    }

    public void setMarketPrice(MarketPrice marketPrice) {
        this._marketPrice = marketPrice;
    }

    public String getCountryISO3() {
        return _market.getCountryISO3();
    }

    public void setCountryISO3(String param) {
        _market.setCountryISO3(param);
    }

    public boolean getDiscountAllowed() {
        return _market.getDiscountAllowed();
    }

    public void setDiscountAllowed(boolean param) {
        _market.setDiscountAllowed(param);
    }

    public int getEventTypeId() {
        return _market.getEventTypeId();
    }

    public void setEventTypeId(int param) {
        _market.setEventTypeId(param);
    }

    public long getLastRefresh() {
        return _market.getLastRefresh();
    }

    public void setLastRefresh(long param) {
        _market.setLastRefresh(param);
    }

    public float getMarketBaseRate() {
        return _market.getMarketBaseRate();
    }

    public void setMarketBaseRate(float param) {
        _market.setMarketBaseRate(param);
    }

    @Transient
    public String getMarketDescription() {
        return _market.getMarketDescription();
    }

    @Transient
    public void setMarketDescription(String param) {
        _market.setMarketDescription(param);
    }

    public boolean getMarketDescriptionHasDate() {
        return _market.getMarketDescriptionHasDate();
    }

    public void setMarketDescriptionHasDate(boolean param) {
        _market.setMarketDescriptionHasDate(param);
    }

    @Transient
    public Calendar getMarketDisplayTime() {
        return _market.getMarketDisplayTime();
    }

    @Transient
    public void setMarketDisplayTime(Calendar param) {
        _market.setMarketDisplayTime(param);
    }

    public int getMarketId() {
        return _market.getMarketId();
    }

    public void setMarketId(int param) {
        _market.setMarketId(param);
    }

    public MarketStatusEnum getMarketStatus() {
        return _market.getMarketStatus();
    }

    public void setMarketStatus(MarketStatusEnum param) {
        _market.setMarketStatus(param);
    }

    public Calendar getMarketSuspendTime() {
        return _market.getMarketSuspendTime();
    }

    public void setMarketSuspendTime(Calendar param) {
        _market.setMarketSuspendTime(param);
    }

    public Calendar getMarketTime() {
        return _market.getMarketTime();
    }

    public void setMarketTime(Calendar param) {
        _market.setMarketTime(param);
    }

    public String getMarketType() {
        return _market.getMarketType().toString();
    }

    public void setMarketType(String param) {
        _market.setMarketType(MarketTypeEnum.Factory.fromValue(param));
    }

    public String getMenuPath() {
        return _market.getMenuPath();
    }

    public void setMenuPath(String param) {
        _market.setMenuPath(param);
    }

    @Transient
    public ArrayOfEventId getEventHierarchy() {
        return _market.getEventHierarchy();
    }

    @Transient
    public void setEventHierarchy(ArrayOfEventId param) {
        _market.setEventHierarchy(param);
    }

    public String getName() {
        return _market.getName();
    }

    public void setName(String param) {
        _market.setName(param);
    }

    public int getNumberOfWinners() {
        return _market.getNumberOfWinners();
    }

    public void setNumberOfWinners(int param) {
        _market.setNumberOfWinners(param);
    }

    public int getParentEventId() {
        return _market.getParentEventId();
    }

    public void setParentEventId(int param) {
        _market.setParentEventId(param);
    }

    @Transient
    public ArrayOfRunner getRunners() {
        return _market.getRunners();
    }

    @Transient
    public void setRunners(ArrayOfRunner param) {
        _market.setRunners(param);
    }

    @Transient
    public Map<Integer, Runner> getRunnerMap() {
        return _runners;
    }

    public String getUnit() {
        return _market.getUnit();
    }

    public void setUnit(String param) {
        _market.setUnit(param);
    }

    public double getMaxUnitValue() {
        return _market.getMaxUnitValue();
    }

    public void setMaxUnitValue(double param) {
        _market.setMaxUnitValue(param);
    }

    public double getMinUnitValue() {
        return _market.getMinUnitValue();
    }

    public void setMinUnitValue(double param) {
        _market.setMinUnitValue(param);
    }

    public double getMarketInterval() {
        return _market.getInterval();
    }

    public void setMarketInterval(double param) {
        _market.setInterval(param);
    }

    public boolean getRunnersMayBeAdded() {
        return _market.getRunnersMayBeAdded();
    }

    public void setRunnersMayBeAdded(boolean param) {
        _market.setRunnersMayBeAdded(param);
    }

    public String getTimezone() {
        return _market.getTimezone();
    }

    public void setTimezone(String param) {
        _market.setTimezone(param);
    }

    public int getLicenceId() {
        return _market.getLicenceId();
    }

    public void setLicenceId(int param) {
        _market.setLicenceId(param);
    }

    @Transient
    public ArrayOfCouponLinks getCouponLinks() {
        return _market.getCouponLinks();
    }

    @Transient
    public void setCouponLinks(ArrayOfCouponLinks param) {
        _market.setCouponLinks(param);
    }

    public boolean getBspMarket() {
        return _market.getBspMarket();
    }

    public void setBspMarket(boolean param) {
        _market.setBspMarket(param);
    }
}
